package com.softserveinc.autorent.model;

import java.io.Serializable;
import javax.persistence.*;

import java.util.Arrays;
import java.util.List;


/**
 * The persistent class for the vendor database table.
 * 
 */
@Entity
@Table(name="car_vendor")
@NamedQueries({
@NamedQuery(name = "CarVendor.findAll", query = "SELECT v FROM CarVendor v"),
@NamedQuery(name = "CarVendor.findById", query = "SELECT v FROM CarVendor v WHERE v.id = :id")
})
public class CarVendor implements Serializable {


	/**
	 * 
	 */
	private static final long serialVersionUID = -7311814537574059236L;

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@Column(unique=true, nullable=false)
	private int id;

	@Lob
	@Basic(fetch=FetchType.LAZY)
	@Column(nullable=true/*, length=5000*/)	
	protected byte[] logo;

	@Column(unique=true, nullable=false, length=50)
	private String name;

	@OneToMany(mappedBy="carVendor")
	private List<CarModel> carModels;

	public CarVendor() {
		super();
	}
	

	public CarVendor(byte[] logo, String name) {
		this.logo = logo;
		this.name = name;
	}


	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public byte[] getLogo() {
		return this.logo;
	}

	public void setLogo(byte[] logo) {
		this.logo = logo;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<CarModel> getCarModels() {
		return this.carModels;
	}

	public void setCarModels(List<CarModel> carModels) {
		this.carModels = carModels;
	}


	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((carModels == null) ? 0 : carModels.hashCode());
		result = prime * result + id;
		result = prime * result + Arrays.hashCode(logo);
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}


	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		CarVendor other = (CarVendor) obj;
		if (carModels == null) {
			if (other.carModels != null)
				return false;
		} else if (!carModels.equals(other.carModels))
			return false;
		if (id != other.id)
			return false;
		if (!Arrays.equals(logo, other.logo))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}
	@Override
	public String toString()
	{
		return this.getId()+","+this.getName();
	}
	
}